<?php

namespace Home\Model;

use Think\Model;

class SubscribeUserModel extends Model {
	
	protected $_auto = array(
		array('create_time', 'time', self::MODEL_BOTH, 'function')
	);
	
	protected $_validate = array();
	
	// 表单显示字段验证配置
	public $items = array (
		"name" => array('val'=>array(array('name', 'require', '姓名不能为空'),)),
		"tel" => '',
		"address" => '',
		"sex" => '',
		"idnum" => '',
		"birthday" => array('auto'=>array(array('birthday', 'strtotime', self::MODEL_BOTH, 'function')),),
		"age" => '',
	    'license'=> array('val'=>array(array('license', 'require', '驾照不能为空'),)),
	    "car" => '',
	    "date" => array('auto'=>array(array('date', 'strtotime', self::MODEL_BOTH, 'function')),),
	);
	
	/**
	 * 安装自动值与验证
	 * @param unknown $items
	 */
	public function setupAutoAndValidate($items) {
		foreach (explode(',', $items) as $v) {
			if(is_array($this->items[$v])) {
				empty($this->items[$v]['val']) or $this->_validate = array_merge($this->_validate, $this->items[$v]['val']);
				empty($this->items[$v]['auto']) or	$this->_auto = array_merge($this->_validate, $this->items[$v]['auto']);
			}
		}
	}
}
